//package com.scm.filter;
//
///**
// * @author CHL
// * @ClassName: PermissionFilter
// * @Description: TODO
// * @date 2022/3/8 15:14
// * @Version 1.0
// */
//import com.scm.dao.UserModelMapper;
//import com.scm.entity.UserModel;
//import java.io.IOException;
//import java.io.PrintStream;
//import java.io.PrintWriter;
//import java.util.HashMap;
//import javax.servlet.Filter;
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.annotation.Order;
//
//@WebFilter(urlPatterns={"/main/*"}, filterName="PermissionFilter")
//@Order(4)
//public class PermissionFilter
//        implements Filter
//{
//    @Autowired
//    private UserModelMapper userModelMapper;
//
//    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
//            throws IOException, ServletException
//    {
//        HttpServletRequest req = (HttpServletRequest)arg0;
//        String uri = req.getRequestURI().substring(1);
//        if ((uri.startsWith("main/sell/product/show")) || (uri.startsWith("main/sell/product/all")))
//        {
//            arg2.doFilter(arg0, arg1);
//            return;
//        }
//        String[] str = uri.split("/");
//        StringBuilder modelUri = new StringBuilder("/");
//        if (str.length >= 2)
//        {
//            modelUri.append(str[0]).append("/").append(str[1]);
//            String account = (String)req.getAttribute("login");
//            HashMap<String, Object> map = new HashMap();
//            map.put("account", account);
//            map.put("modelUri", modelUri.toString());
//            UserModel um = this.userModelMapper.isAllow(map);
//            if (um != null)
//            {
//                arg2.doFilter(arg0, arg1);
//                return;
//            }
//            arg1.setCharacterEncoding("utf-8");
//            arg1.setContentType("text/json;charset=utf-8");
//            PrintWriter out = arg1.getWriter();
//            out.print("{\"status\": 1, \"statusInfo\": \"您当前没有权限访问，请联系管理员\"");
//            out.flush();
//            out.close();
//        }
//        else
//        {
//            arg2.doFilter(arg0, arg1);
//        }
//    }
//}
//
